home *** CD-ROM | disk | FTP | other *** search
/ The X-Philes (2nd Revision) / The X-Philes Number 1 (1995).iso / xphiles / hp48_2 / disasm.tar / disasm / trace.c < prev   
C/C++ Source or Header  |  1990-04-25  |  1KB  |  79 lines

  1. #include "dis48.h"
  2. #include <fcntl.h>
  3.  
  4. #define NSIZE 524288
  5. #define BSIZE (NSIZE / 2)
  6.  
  7. Bitmap    completed;
  8. int    dopause = 0;
  9.  
  10. #ifdef ANSI
  11. main(int argc, char **argv)
  12. #else
  13. main(argc, argv)
  14. int    argc;
  15. char    **argv;
  16. #endif
  17. {
  18.     char    *p;
  19.     int    n;
  20.     int    s, e;
  21.     char    buf[80];
  22.     char    *mem, *malloc();
  23.     
  24.     if ((argc > 1) && !strcmp(argv[1], "-p"))
  25.         dopause = 1;
  26.         
  27.     if ((mem = malloc(BSIZE)) == NULL) {
  28.         fprintf(stderr, "malloc failed\n");
  29.         exit(1);
  30.     }
  31.     
  32.     if ((completed = malloc(BITS(NSIZE))) == NULL) {
  33.         fprintf(stderr, "malloc failed\n");
  34.         goto done;
  35.     }
  36.     
  37.     memset(completed, 0, BITS(NSIZE));
  38.     if ((n = open("rom", O_RDONLY)) < 0) {
  39.         fprintf(stderr, "open failed\n");
  40.         goto done2;
  41.     }
  42.     
  43.     if (read(n, mem, BSIZE) != BSIZE) {
  44.         fprintf(stderr, "read failed\n");
  45.         close(n);
  46.         goto done2;
  47.     }
  48.     
  49.     (void) close(n);
  50.     fprintf(stderr, "start?\n");
  51.     if (fgets(buf, sizeof(buf), stdin) == NULL)
  52.         goto done2;
  53.         
  54.     if (sscanf(buf, "%x", &s) != 1)
  55.         goto done2;
  56.         
  57.     Disassemble(mem, s, NOADDR, stdout);
  58.     for (s = 0; s < 0x80000;) {
  59.         while (!BITTEST(completed, s))
  60.             s++;
  61.             
  62.         e = s;
  63.         while (BITTEST(completed, e) && (e < 0x80000))
  64.             e++;
  65.         
  66.         e--;
  67.         printf("\n");
  68.         /*fprintf(stderr, "S: %05x E: %05x\n", s, e);*/
  69.         Disassemble(mem, s, e, stdout);
  70.         s = ++e;
  71.     }
  72.     
  73. done2:
  74.     free(completed);
  75. done:    
  76.     free(mem);
  77.     exit(0);
  78. }
  79.